<?php
// $Id: admin_functions.php 229 2008-03-03 13:27:42Z mikhail.miguel $

// 2007-07-22 K.OHWADA
// admin can add etc column

// 2007-06-01 K.OHWADA
// menu: preference.php blocks.php
// rssc_view_handler

// 2007-05-18 K.OHWADA
// XC 2.1: preferences

// 2007-02-20 K.OHWADA
// hack for multi site

// 2006-10-01 K.OHWADA
// use happy_linux
// use rssc WEBLINKS_RSSC_EXIST
// remove weblinks_admin_check_token()

// 2006-05-15 K.OHWADA
// weblinks_admin_print_header()
// weblinks_admin_print_menu()

// 2006-03-22 K.OHWADA
// use new handler: votedata

// 2006-01-01 K.OHWADA
// weblinks ver 1.0
// module depulication
// from include/functions

//=========================================================
// WebLinks Module
// admin functions
// 2004-12-05 K.OHWADA
//=========================================================
function weblinks_admin_print_header()
{
	echo "<h3>"._MI_WEBLINKS_NAME."</h3>\n";
	echo _MI_WEBLINKS_DESC."<br /><br />\n";
}

function weblinks_admin_print_bread( $name1, $url1='', $name2='' )
{
	$system =& happy_linux_system::getInstance();
	$form   =& happy_linux_form::getInstance();

	$arr = array(
		array(
			'name' => $system->get_module_name(),
			'url'  => 'index.php',
		),
	);

	if ( $name1 )
	{
		$arr[] = array(
			'name' => $name1,
			'url'  => $url1,
		);
	}

	if ( $name2 )
	{
		$arr[] = array(
			'name' => $name2,
		);
	}

	echo $form->build_html_bread_crumb( $arr );
}

function weblinks_admin_print_menu()
{
	$MAX_COL = 4;

	$link_handler    =& weblinks_get_handler('link',      WEBLINKS_DIRNAME);
	$cat_handler     =& weblinks_get_handler('category',  WEBLINKS_DIRNAME);
	$modify_handler  =& weblinks_get_handler('modify',    WEBLINKS_DIRNAME );
	$broken_handler  =& weblinks_get_handler('broken',    WEBLINKS_DIRNAME );
	$vote_handler    =& weblinks_get_handler('votedata',  WEBLINKS_DIRNAME );
	$catlink_handler =& weblinks_get_handler('catlink',   WEBLINKS_DIRNAME );

	$form =& happy_linux_form::getInstance();

	$total_link    = $link_handler->getCount();
	$total_cat     = $cat_handler->getCount();
	$total_vote    = $vote_handler->getCount();
	$total_catlink = $catlink_handler->getCount();

	$total_brokenlinks = $link_handler->get_count_broken();
	$total_brokenlinks = $form->build_html_highlight_number($total_brokenlinks);

	$total_newlinks = $modify_handler->get_count_new();
	$total_newlinks = $form->build_html_highlight_number($total_newlinks);

	$total_modify = $modify_handler->get_count_mod();
	$total_modify = $form->build_html_highlight_number($total_modify);

	$total_broken = $broken_handler->getCount();
	$total_broken = $form->build_html_highlight_number($total_broken);

	$total_nourl  = $link_handler->get_count_non_url();
	$link_list    = _WEBLINKS_ADMIN_LINK_LIST.     " ($total_link)";
	$cat_list     = _WEBLINKS_ADMIN_CATEGORY_LIST. " ($total_cat)";
	$vote_list    = _AM_WEBLINKS_VOTE_LIST.        " ($total_vote)";
	$catlink_list = _AM_WEBLINKS_CATLINK_LIST.     " ($total_catlink)";

	$title_link = _WEBLINKS_ADMIN_LINK_MANAGE."<br />"._WEBLINKS_ADMIN_ADD_LINK;

	$title_brokenlinks = _WEBLINKS_ADMIN_LINK_BROKEN." ($total_brokenlinks)";
	$title_newlinks    = _WLS_LINKSWAITING. " ($total_newlinks)";
	$title_modify      = _WLS_MODREQUESTS.  " ($total_modify)";
	$title_broken      = _WLS_BROKENREPORTS." ($total_broken)";

	$config_0 = _AM_WEBLINKS_MODULE_CONFIG_0 .  '<br /> ('._AM_WEBLINKS_MODULE_CONFIG_DESC_0.') '; 
	$config_2 = _WEBLINKS_ADMIN_MODULE_CONFIG_2.'<br /> ('._AM_WEBLINKS_MODULE_CONFIG_DESC_2.') '; 
	$config_3 = _AM_WEBLINKS_MODULE_CONFIG_3 .  '<br /> ('._AM_WEBLINKS_MODULE_CONFIG_DESC_3.') '; 
	$config_4 = _AM_WEBLINKS_MODULE_CONFIG_4 .  '<br /> ('._AM_WEBLINKS_MODULE_CONFIG_DESC_4.') '; 
	$config_5 = _AM_WEBLINKS_MODULE_CONFIG_5 .  '<br /> ('._AM_WEBLINKS_MODULE_CONFIG_DESC_5.') '; 
	$config_6 = _AM_WEBLINKS_MODULE_CONFIG_6 .  '<br /> ('._AM_WEBLINKS_MODULE_CONFIG_DESC_6.') '; 

	if ( WEBLINKS_RSSC_EXIST )
	{
		$rssc_handler =& weblinks_get_handler( 'rssc_view', WEBLINKS_DIRNAME );
		$total_feed   =  $rssc_handler->get_feed_count_all();
		$url_rssc_feed_list = WEBLINKS_RSSC_URL.'/admin/archive_manage.php';
	}
	else
	{
		$total_feed = 0;
		$url_rssc_feed_list = '';
	}

	$feed_list = _WEBLINKS_ADMIN_RSS_MANAGE.    " ($total_feed)";

	$menu_arr = array(

		$config_0                       => 'index.php',
		_WEBLINKS_ADMIN_MODULE_CONFIG_1 => 'preferences.php',
		$config_2                       => 'config_manage_2.php',
		$config_3                       => 'config_manage_3.php',

		$config_4                       => 'config_manage_4.php',
		$config_5                   => 'config_manage_5.php',
		$config_6                   => 'config_manage_6.php',
		_AM_WEBLINKS_MAP_JP_MANAGE  => 'map_jp_manage.php',

		$cat_list     => 'category_list.php',
		$link_list    => 'link_list.php',
		$vote_list    => 'votedata_list.php',
		$catlink_list => 'catlink_list.php',

		_AM_WEBLINKS_ADD_CATEGORY         => 'category_manage.php',
		_WEBLINKS_ADMIN_ADD_LINK          => 'link_manage.php',
		_AM_WEBLINKS_BULK_IMPORT          => 'bulk_manage.php',
		_WEBLINKS_ADMIN_LINK_BROKEN_CHECK => 'link_broken_check.php',

		$title_newlinks           => 'modify_list.php?sortid=2',
		$title_modify             => 'modify_list.php?sortid=3',
		$title_brokenlinks        => 'link_list.php?sortid=2',
		$title_broken             => 'broken_list.php',

		_WEBLINKS_ADMIN_USER_MANAGE        => 'user_list.php',
		_WEBLINKS_ADMIN_SENDMAIL           => 'mail_users.php',
		_AM_WEBLINKS_COMMAND_MANAGE  => 'command_manage.php',
		_AM_WEBLINKS_TABLE_MANAGE    => 'table_manage.php',

		_AM_WEBLINKS_IMPORT_MANAGE   => 'import_manage.php',
		_AM_WEBLINKS_EXPORT_MANAGE   => 'export_manage.php',
		_HAPPY_LINUX_AM_BLOCK        => 'blocks.php',
		_AM_WEBLINKS_COLUMN_MANAGE  => 'column_manage.php',

		$feed_list                   => $url_rssc_feed_list,
		'.'                         => '',
		'..'                        => '',
		_GOTO_MODULE => '../index.php'
	);

	$form =& happy_linux_form::getInstance();
	echo $form->build_html_menu_table($menu_arr, $MAX_COL);

}

function weblinks_admin_print_footer()
{

?>
<hr />
<div align="right"><a href="http://linux2.ohwada.net/" target="_blank"><font size="-1">Powered by Happy Linux</font></a></div>
<div align="right"><font size="-1">&copy; 2005, Kenichi OHWADA</font></div>
<?php

}

//---------------------------------------------------------
// hack for multi site
//---------------------------------------------------------
function weblinks_admin_multi_disable_feature()
{
	if ( weblinks_multi_is_english_site() )
	{
		redirect_header( 'index.php', 1, _WEBLINKS_DISABLE_FEATURE);
	}
}

function weblinks_admin_multi_redirect_jp_site()
{
	if ( weblinks_multi_is_english_site() )
	{
// Engilsh site goto Japanese site
		$url    = xoops_getenv('REQUEST_URI');
		$url_jp = str_replace('/en/', '/jp/', $url);
		redirect_header( $url_jp, 1, _WEBLINKS_REDIRECT_JP_SITE);
	}
}

?>